package config_center

import (
	"gorm.io/gorm"
	"payme3000/framework/db"
)

// GetGorm 返回gorm的连接实例, 调用方不能缓存该连接实例, 会因为配置变更而更换连接实例
func (c *ConfigCenter) GetGorm(dbType db.Type) *gorm.DB {
	gormDb := db.GetGorm(dbType)
	if gormDb != nil {
		return gormDb
	}

	if err := c.initDb(dbType); err != nil {
		return nil
	}

	return db.GetGorm(dbType)
}
